package com.fqgj.sentry.biz.mc;

import com.fqgj.sentry.common.utils.ApiPage;
import com.fqgj.sentry.manage.entity.McLogEntity;
import com.fqgj.sentry.manage.service.LogService;
import com.fqgj.sentry.biz.mc.vo.log.LogInfoVo;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ykpbean kangping.ying@yuntu-inc.com
 *
 * @description
 * @create 2017-07-15 下午8:17
 */

@Component
public class LogBusiness {
    @Autowired
    private LogService logService;

    public ApiPage queryLogListForPage(Long userId, String email, Integer pageNum, Integer pageSize) {

        Page<McLogEntity> logEntityList = logService.selectLogListForPage(userId, email, pageNum, pageSize);
        List<LogInfoVo> logInfoVoList = new ArrayList<>();
        for (McLogEntity logEntity : logEntityList.getResult()) {
            LogInfoVo logInfoVo = new LogInfoVo()
                    .setEmail(logEntity.getEmail())
                    .setBrowser(logEntity.getBrowser())
                    .setIp(logEntity.getIp())
                    .setUri(logEntity.getUri())
                    .setOperateSys(logEntity.getOperateSys());
            logInfoVo.setGmtCreate(logEntity.getGmtCreate());
            logInfoVoList.add(logInfoVo);
        }
        ApiPage apiPage=new ApiPage()
                .setPageNum(pageNum)
                .setPageSize(pageSize)
                .setTotal(logEntityList.getTotal())
                .setData(logInfoVoList);
        return apiPage;
    }


}
